<script setup>
import { ref, onMounted, defineProps } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getMyVideoAPI, getMyPublishCourse } from '@/services/course'
const videoInfoList = ref()
const getMyCourseService = async (status) => {
  const res = await getMyVideoAPI(status)
  res.data.forEach((item) => {
    const { publishStatus, submitStatus, auditStatus } = item
    item.submitStatus = submitStatus === '301' ? '未提交审核' : '已提交审核'
    item.publishStatus = publishStatus === '201' ? '未发布' : '已发布'
    item.auditStatus =
      auditStatus === '101' ? '审核通过' : auditStatus === '102' ? '审核不通过' : '待审核'
  })
  videoInfoList.value = res.data
}
const getMyPublishCourseSerivce = async () => {
  const res = await getMyPublishCourse()
  res.data.forEach((item) => {
    const { status } = item
    item.status = status === '0' ? '已下架' : '线上'
  })
  videoInfoList.value = res.data
}
onMounted(() => {
  changeIndex(0)
})
onLoad((index = '0') => {
  changeIndex(index) //从子页面跳转过来并携带了index参数
})
const rightText = ref('')
const currentIndex = ref(0)
const changeIndex = async (index) => {
  switch (index) {
    case 0:
      currentIndex.value = 0
      await getMyCourseService('103')
      rightText.value = '修改信息'
      break
    case 1:
      currentIndex.value = 1
      await getMyCourseService('101')
      rightText.value = '发布'
      break
    case 2:
      currentIndex.value = 2
      await getMyCourseService('102')
      rightText.value = '查看审核建议'
      break
    case 3:
      currentIndex.value = 3
      await getMyPublishCourseSerivce()
      rightText.value = '展示情况'
      break
  }
}
const list = ref(['待审核', '审核通过', '审核不通过', '已发布视频'])
const onClick = () => {
  uni.navigateTo({
    url: `/pages/learn/info?auditStatus=待审核`,
  })
}
const getNeedNote = (item) => {
  switch (currentIndex.value) {
    case 0:
      return item.submitStatus
    case 1:
      return item.publishStatus
    case 3:
      return item.status
    default:
      return ''
  }
}
</script>
<template>
  <view style="position: relative; height: 90vh">
    <uv-subsection
      :list="list"
      :current="currentIndex"
      mode="button"
      fontSize="26rpx"
      bold
      custom-style="height: 80rpx;"
      activeColor="black"
      @change="changeIndex"
      bgColor="#456b45"
    ></uv-subsection>
    <uv-list border>
      <view v-for="item in videoInfoList" :key="item.id">
        <uv-list-item
          ellipsis="2"
          link
          :to="'/pages/learn/info?id=' + item.id + '&index=' + currentIndex"
          border="true"
          show-badge
          clickable
          :title="item.title"
          :note="getNeedNote(item)"
          :thumb="
            item.url + '?spm=qipa250&x-oss-process=video/snapshot,t_7000,f_jpg,w_0,h_0,m_fast'
          "
          thumb-size="lg"
          :right-text="rightText"
        >
        </uv-list-item>
      </view>
    </uv-list>
  </view>
  <view style="width: 50%; margin: 0 auto"
    ><uv-button
      type="primary"
      text="上传视频到科普课堂"
      :custom-style="customStyle"
      @click="onClick"
    ></uv-button
  ></view>
</template>

<style>
.text {
  font-size: 20rpx;
  color: #545454;
}
</style>
